package com.qqqq.web.user;

import com.qqqq.code.AjaxResult;
import com.qqqq.code.BaseHttpServlet;
import com.qqqq.dao.impl.UserDaoImpl;
import com.qqqq.domain.User;
import com.qqqq.service.IUserService;
import com.qqqq.service.impl.UserServiceImpl;
import com.qqqq.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user_look")
public class SelectServlet extends BaseHttpServlet {
    private IUserService userService;

    @Override
    public void init() throws ServletException {
        userService = new UserServiceImpl(new UserDaoImpl());
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        if (!req.getParameterMap().containsKey("id")) {
            ResponseUtils.responseJson(resp, AjaxResult.error(400, "请传入id"));
            return;
        }
        int id = Integer.parseInt(req.getParameter("id"));
//        User user = RequestUtils.getReqJsonBody(req, );

        executeBusiness(resp, response -> {
            User user = userService.getUser(id);
            ResponseUtils.responseJson(resp, AjaxResult.success(user));
        });


    }
}
